package com.texas_android.app.View.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.gson.reflect.TypeToken;
import com.texas_android.app.Appconfig.AppContext;
import com.texas_android.app.R;
import com.texas_android.app.http.ResponseHandler;
import com.texas_android.app.http.bean.EvaluateInfoBean;
import com.texas_android.app.http.bean.perssion.PerssionBean;
import com.texas_android.app.utils.AppOperator;
import com.universal_library.fragment.BaseFragment;

import butterknife.Bind;
import cz.msebera.android.httpclient.Header;

/**
 * Created by solin on 2018/3/14.
 */

public class OneFragment extends BaseFragment {
    @Bind(R.id.tv_dutyType)
    TextView tv_dutyType;

    @Bind(R.id.tv_permission)
    TextView tv_permission;

    @Bind(R.id.tv_perTrait)
    TextView tv_perTrait;

    @Bind(R.id.tv_perStyle)
    TextView tv_perStyle;

    @Bind(R.id.tv_capacityType)
    TextView tv_capacityType;

    @Bind(R.id.tv_leaderType)
    TextView tv_leaderType;

    @Bind(R.id.tv_masses)
    TextView tv_masses;

    @Bind(R.id.tv_incorrupt)
    TextView tv_incorrupt;

    @Bind(R.id.tv_spiritStatus)
    TextView tv_spritStatus;
    @Bind(R.id.tv_compatible)
    TextView tv_compatible;

    @Bind(R.id.tv_virtueEvaluate)
    TextView tv_virtueEvaluate;

    @Bind(R.id.tv_potential)
    TextView tv_potential;

    @Bind(R.id.tv_healthStatus)
    TextView tv_healthStatus;

    @Bind(R.id.tv_other)
    TextView tv_other;

    private int perId;
    private PerssionBean perBean;

    @Override
    public void initBundle(Bundle mBundle) {
        super.initBundle(mBundle);
        if (mBundle != null && mBundle.getInt("perId") != 0)
            perId = mBundle.getInt("perId");
        perBean = (PerssionBean) mBundle.getSerializable("persion");

    }

    private ResponseHandler handler = new ResponseHandler(getActivity(), false, "基本评价接口") {
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, String responseString) {
            super.onSuccess(statusCode, headers, responseString);
            if (baseBean.getStatus().equals("0")) {
                EvaluateInfoBean infoBean = AppOperator.createGson().fromJson(responseString,
                        new TypeToken<EvaluateInfoBean>() {
                        }.getType());
                initViewData(infoBean);
            }
        }
    };

    private void initViewData(EvaluateInfoBean infoBean) {


        tv_dutyType.setText(infoBean.getDutyType());
        tv_permission.setText(infoBean.getPermission());
        tv_perTrait.setText(infoBean.getPerTrait());
        tv_perStyle.setText(infoBean.getPerStyle());
        tv_capacityType.setText(infoBean.getCapacityType());
        tv_leaderType.setText(infoBean.getLeaderType());
        tv_masses.setText(infoBean.getMasses());
        tv_incorrupt.setText(infoBean.getIncorrupt());
        tv_spritStatus.setText(infoBean.getSpiritStatus());
        tv_compatible.setText(infoBean.getCompatible());
        tv_virtueEvaluate.setText(infoBean.getVirtueEvaluate());
        tv_potential.setText(infoBean.getPotential());
        tv_potential.setText(infoBean.getPotential());
        tv_healthStatus.setText(infoBean.getHealthStatus());
        tv_other.setText(infoBean.getOther());
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_one;
    }

    @Override
    protected void initView(View view) {

    }

    @Override
    protected void initData() {
        if (perBean != null) {
            tv_healthStatus.setText(perBean.getHealthStatus());
            tv_dutyType.setText(perBean.getProfessionalDuty());
        } else {
            perBean = AppContext.getBean();
            tv_healthStatus.setText(perBean.getHealthStatus());
            tv_dutyType.setText(perBean.getProfessionalDuty());
        }
//        Api.getEvaluateInfo(handler, MyApplication.aCache.getAsString(AppConfig.APP_SERVER_TOKEN), perId);
    }
}
